<?php
require_once('../../config.php');
Doctrine::loadModels('../../models');

if ($_REQUEST["agent_id"]) 
{
	$agent_id = strip_tags($_REQUEST["agent_id"]);
	
	$query = $db_query = sprintf("SELECT a.agent_id, a.name_short, a.name_full, 
		a.agent_type_id, a.date_start, a.date_end,
        s.line_of_business_id, s.email, s.phone, s.fax, s.website, s.cvr_number,
        p.item_name line_of_business
	FROM suppliers s
  		INNER JOIN agent a ON s.agent_supplier_id = a.agent_id
  		INNER JOIN lk_glossary p ON s.line_of_business_id = p.item_id 
	WHERE a.agent_id ='".$agent_id."'");
	
	$items = mysql_query($query);	
}

$dom = new DomDocument('1.0',"UTF-8");
$dom->formatOutput = true;
$root = $dom->createElement( "results" );
$dom->appendChild( $root );
	while(($item = mysql_fetch_assoc($items)))
	{
		$dn = $dom->createElement( "record" );
		$dn->setAttribute( 'agent_id', ($item['agent_id']));
		$dn->setAttribute( 'name_short', ($item['name_short']));
		$dn->setAttribute( 'name_full', ($item['name_full']));
		$dn->setAttribute( 'cvr_number', ($item['cvr_number']));
		$dn->setAttribute( 'date_start', $item['date_start'] );
		$dn->setAttribute( 'date_end', $item['date_end'] );
		$dn->setAttribute( 'line_of_business_id', $item['line_of_business_id'] );
		$dn->setAttribute( 'line_of_business', $item['line_of_business'] );
		$dn->setAttribute( 'email', $item['email'] );
		$dn->setAttribute( 'phone', ($item['phone']));
		$dn->setAttribute( 'fax', ($item['fax']));
		$dn->setAttribute( 'website', ($item['website']));
		$root->appendChild( $dn );
	}		
header( "Content-type: text/xml; charset=UTF-8");
echo $dom->saveXML();

?>